﻿using System;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.UI;

namespace ASPNETVN.PORTAL.Modules.DVDZone.Controls
{
    public partial class AddEditItem : AddEditItemControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DownloadHelper.DownloadImage(txtPosterImagePath.Text, "~/Uploads/DVDZONE/Movies/");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            Components.Item item = new Components.Item();
            item.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue);
            item.Title = txtTitle.Text;
            item.SubTitle = txtSubTitle.Text;
            item.CreatedBy = item.LastUpdatedBy = PortalSecurity.CurrentUser.Identity.Email;
            item.LastUpdatedDate = item.CreatedDate = DateTime.Now;

            if (this.ItemID == 0)
            {
                int id = item.Insert();
                // Refresh.
                string url = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, this.ItemID, "page=AddEditItem");
                Response.Redirect(url);
            }
            else
            {
                // Lấy các giá trị từ hidden fields.
                item.ID = this.ItemID;
                item.Update();
            }
        }
    }
}